/*  Copyright 2019 Jimmy Hogoboom
 *
 *  This file is part of crumb.
 *
 *  crumb is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  crumb is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with crumb.  If not, see <https://www.gnu.org/licenses/>.
 */

using System;
using crumb.Api.Core.Domain.Common;

namespace crumb.Api.Core.Domain.Posts
{
    public class Post : IEntity
    {
        private Guid? _id;
        public Guid? Id
        {
            get { return _id; }
            set
            {
                if (ParentPostId.HasValue && ParentPostId == value)
                {
                    throw new InvalidOperationException(
                        "Id cannot be the same as ParentPostId.");
                }
                _id = value;
            }
        }
        public DateTime PostDate { get; set; }
        public string Title { get; set; }
        public string Body { get; set; }

        private Guid? _parentPostId;
        public Guid? ParentPostId
        {
            get { return _parentPostId; }
            set
            {
                // ParentPostId cannot be the same as Id.
                if (Id.HasValue && Id == value)
                {
                    throw new InvalidOperationException(
                        "ParentPostId cannot be the same as Id.");
                }
                _parentPostId = value;
            }
        }

        public Guid AccountId { get; set; }

        public Post(Guid accountId, string body)
        {
            AccountId = accountId;
            Body = body;
        }
    }
}